package com.ruoyi.shopping.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shopping.domain.CommodityEvaluate;
import com.ruoyi.shopping.service.ICommodityEvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品评价管理Controller
 * 
 * @author fxy
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/shopping/commodityEvaluate")
public class CommodityEvaluateController extends BaseController
{
    @Autowired
    private ICommodityEvaluateService commodityEvaluateService;

    /**
     * 查询商品评价管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityEvaluate:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommodityEvaluate commodityEvaluate)
    {
        startPage();
        List<CommodityEvaluate> list = commodityEvaluateService.selectCommodityEvaluateList(commodityEvaluate);
        return getDataTable(list);
    }

    /**
     * 导出商品评价管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityEvaluate:export')")
    @Log(title = "商品评价管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommodityEvaluate commodityEvaluate)
    {
        List<CommodityEvaluate> list = commodityEvaluateService.selectCommodityEvaluateList(commodityEvaluate);
        ExcelUtil<CommodityEvaluate> util = new ExcelUtil<CommodityEvaluate>(CommodityEvaluate.class);
        util.exportExcel(response, list, "商品评价管理数据");
    }
    @PreAuthorize("@ss.hasPermi('shopping:commodityEvaluate:query')")
    @GetMapping(value = "/isEva")
    public AjaxResult isCollection( CommodityEvaluate commodityEvaluate) {
        return success(commodityEvaluateService.queryByCCId(commodityEvaluate));
    }
    /**
     * 获取商品评价管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityEvaluate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commodityEvaluateService.selectCommodityEvaluateById(id));
    }

    /**
     * 新增商品评价管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityEvaluate:add')")
    @Log(title = "商品评价管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommodityEvaluate commodityEvaluate)
    {
        return toAjax(commodityEvaluateService.insertCommodityEvaluate(commodityEvaluate));
    }

    /**
     * 修改商品评价管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityEvaluate:edit')")
    @Log(title = "商品评价管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommodityEvaluate commodityEvaluate)
    {
        return toAjax(commodityEvaluateService.updateCommodityEvaluate(commodityEvaluate));
    }

    /**
     * 删除商品评价管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityEvaluate:remove')")
    @Log(title = "商品评价管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commodityEvaluateService.deleteCommodityEvaluateByIds(ids));
    }

    /**
     * 评价审核功能
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityEvaluate:auditToYes')")
    @Log(title = "商品评价管理", businessType = BusinessType.UPDATE)
    @PutMapping("/auditToYes/{id}")
    public AjaxResult auditToYes(@PathVariable("id") Long id)
    {
        return toAjax(commodityEvaluateService.updateToYes(id));
    }
    @PreAuthorize("@ss.hasPermi('shopping:commodityEvaluate:auditToNo')")
    @Log(title = "商品评价管理", businessType = BusinessType.UPDATE)
    @PutMapping("/auditToNo/{id}")
    public AjaxResult auditToNo(@PathVariable("id") Long id)
    {
        return toAjax(commodityEvaluateService.updateToNo(id));
    }
}
